1 module logger; 2 3 public import std.experimental.logger; 4 5 //TODO: move to Geany logger 6 7 void nothrowLog 8 ( 9 string S, 10 int line = __LINE__, 11 string file = __FILE__, 12 string funcName = __FUNCTION__, 13 string prettyFuncName = __PRETTY_FUNCTION__, 14 string moduleName = __MODULE__, 15 A... 16 ) 17 (lazy string msg) nothrow 18 { 19 try 20 { 21 static if(S == "trace") 22 trace!(line, file, funcName, prettyFuncName, moduleName)(msg); 23 else static if(S == "info") 24 info!(line, file, funcName, prettyFuncName, moduleName)(msg); 25 else static if(S == "warning") 26 warning!(line, file, funcName, prettyFuncName, moduleName)(msg); 27 else static if(S == "error") 28 error!(line, file, funcName, prettyFuncName, moduleName)(msg); 29 else static if(S == "fatal") 30 fatal!(line, file, funcName, prettyFuncName, moduleName)(msg); 31 else 32 static assert(false, "Unsupported log type"); 33 } 34 catch(Exception e) 35 { 36 // TODO: pass error to unthrowable geany logger 37 assert(false); 38 } 39 } 40 41 void nothrowLog 42 ( 43 string S, 44 int line = __LINE__, 45 string file = __FILE__, 46 string funcName = __FUNCTION__, 47 string prettyFuncName = __PRETTY_FUNCTION__, 48 string moduleName = __MODULE__, 49 A... 50 ) 51 (Exception e) nothrow 52 { 53 import std.conv: to; 54 import std.exception: assumeWontThrow; 55 56 string msg = e.file~':'~e.line.to!string~':'~e.msg~"\nStack trace:\n"~assumeWontThrow(e.info.to!string); 57 58 try 59 { 60 static if(S == "trace") 61 trace!(line, file, funcName, prettyFuncName, moduleName)(msg); 62 else static if(S == "info") 63 info!(line, file, funcName, prettyFuncName, moduleName)(msg); 64 else static if(S == "warning") 65 warning!(line, file, funcName, prettyFuncName, moduleName)(msg); 66 else static if(S == "error") 67 error!(line, file, funcName, prettyFuncName, moduleName)(msg); 68 else static if(S == "fatal") 69 fatal!(line, file, funcName, prettyFuncName, moduleName)(msg); 70 else 71 static assert(false, "Unsupported log type"); 72 } 73 catch(Exception e) 74 { 75 // TODO: pass error to unthrowable geany logger 76 assert(false); 77 } 78 }